package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpGender;
import com.itheima.pojo.EmpJob;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
    @Select("select e.*, d.name deptName from emp e left join dept d on e.dept_id = d.id")
    List<Emp> selectEmp();

    List<Emp> demoSearch(String name,Integer gender);

    Page<Emp> page(String name, Integer gender, LocalDate begin, LocalDate end);

    //添加员工
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into emp(username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{password}, #{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    //案例
    List<Emp> fore(int[] as);


    //删除员工信息
    void deleteByIds(List<Integer> ids);

    //修改员工-查询回显
    Emp selectById(Integer id);

    //修改员工
    void updateEmp(Emp emp);

    //员工职位人数统计
    @Select("select case job" +
            "    when 1 then '班主任'" +
            "    when 2 then '讲师'" +
            "    when 3 then '学工主管'" +
            "    when 4 then '教研主管'" +
            "    when 5 then '咨询师'" +
            "    else '其他'" +
            "    end job,count(*) cot from emp group by job")
    List<EmpJob> empJobData();


    @Select("select case gender" +
            "           when 1 then '男性员工'" +
            "           else '女性员工'" +
            "           end name,count(*) value from emp group by gender;")
    List<EmpGender> empGender();

    //查询全部员工
    @Select("select * from emp")
    List<Emp> selectAllEmp();

    /**
     * 登录
     */
    @Select("select * from emp where username=#{username} and password = #{password}")
    Emp login(Emp emp);
}